package com.tbit.uqbike.constant.enums;

import com.tbit.uqbike.constant.MachineFunctionConstant;
import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author yee_
 * @date 2023/11/7
 * 设备功能绑定的模式
 */
@Getter
public enum MachineFunctionModeEnum {
    /**
     *
     */
    HUAHUI_PEDAL_WITH_COLOR_CARD(MachineFunctionConstant.PHOTO_RETURN_CAR, 1, "拍摄脚踏板+颜色卡（三方方案）"),
    PEDAL_WITH_COLOR_CARD(MachineFunctionConstant.PHOTO_RETURN_CAR, 2, "拍摄脚踏板+颜色卡"),
    BICYCLE_SEAT_CUSHION(MachineFunctionConstant.PHOTO_RETURN_CAR, 3, "拍摄车辆坐垫（仅支持自行车）"),
    //MACHINE_LICENSE_PLATE(MachineFunctionConstant.PHOTO_RETURN_CAR, 4, "自研拍电动车车牌"),
    PEDAL(MachineFunctionConstant.PHOTO_RETURN_CAR, 5, "拍摄脚踏板"),
    MACHINE_PEDAL_PLATE(MachineFunctionConstant.PHOTO_RETURN_CAR, 6, "拍摄脚踏板+车头停车线"),
    MACHINE_TAIL_PLATE(MachineFunctionConstant.PHOTO_RETURN_CAR, 7, "拍摄车辆后座+车尾停车线"),
    //MACHINE_PEDAL_LICENSE_PLATE(MachineFunctionConstant.PHOTO_RETURN_CAR, 8, "自研拍车牌(识别脚踏板停车线+车牌)"),
    MACHINE_TAIL_LICENSE_PLATE(MachineFunctionConstant.PHOTO_RETURN_CAR, 9, "拍摄车辆车牌+车尾停车线"),
    ;

    private final Integer functionType;

    private final Integer modeCode;
    private final String modeName;

    MachineFunctionModeEnum(Integer functionType, Integer modeCode, String modeName) {
        this.functionType = functionType;
        this.modeCode = modeCode;
        this.modeName = modeName;
    }

    public static List<Map<String, String>> getFunctionModeByType(Integer functionType) {
        if (functionType == null) {
            return Collections.emptyList();
        }
        Map<Integer, List<Map<String, String>>> functionModeBindMap = Arrays.stream(MachineFunctionModeEnum.values())
                .collect(Collectors.groupingBy(MachineFunctionModeEnum::getFunctionType,
                        Collectors.mapping(value -> {
                            HashMap<String, String> map = new HashMap<>();
                            map.put("key", value.modeCode.toString());
                            map.put("value", value.modeName);
                            return map;
                        }, Collectors.toList())));
        return functionModeBindMap.getOrDefault(functionType, Collections.emptyList());
    }

}
